home *** CD-ROM | disk | FTP | other *** search
- Path: news.lpr.carel.fi!usenet
- From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
- Newsgroups: comp.lang.c
- Subject: Re: Type conversion
- Date: Tue, 30 Jan 1996 14:55:47 +0200
- Organization: Carelcomp Forest
- Message-ID: <310E1553.512C@cmt.lpr.mail.carel.fi>
- References: <4ejjka$2rf@news3.cts.com>
- NNTP-Posting-Host: renoir.cclahti.carel.fi
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b6a (WinNT; I)
-
- Jim Fitzgerald wrote:
- >
- > Hi,
- >
- > Was wondering if a guru out there could tell me why the following
- > code fragment for extracting an long from a buffer does not work.
- > Following the bad code, is a fragment that does work.. but is fairly
- > cheezy! )..
- >
- > This code compiles and runs but returns INCORRECT results:
- >
- > char buffer[512];
- > long node_left, node_right;
- > {
- > node_left = (long)*(buffer+4);
- > node_right= (long)*(buffer+8);
- > }
- >
- > This code runs and returns CORRECT results:
- >
- > char buffer[512];
- > long node_left, node_right;
- > long *bogus;
- > {
- > bogus = buffer+4;
- > node_left = *bogus;
- > bogus = buffer+8;
- > node_right= *bogus;
- > }
- >
- > Thanks!
- > -Jim
-
- This should also work:
- char buffer[512];
- long node_left, node_right;
- {
- node_left = *((long*)(buffer+4));
- node_right= *((long*)(buffer+8));
- }
-
-
- --
- All my opinions are mine and mine alone.
-